package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.po.ExamWarehouse;
import com.zhijian.medical.entity.vo.request.ExamWarehouseSearchVo;
import com.zhijian.medical.entity.vo.response.ExamWarehouseVo;
import com.zhijian.medical.service.ExamWarehouseService;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考核-题库 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-01-16 15:14:10
 */
@Slf4j
@Controller
@Api(tags = "考核-题库")
public class ExamWarehouseController {

    @Autowired
    private ExamWarehouseService service;

//    /**
//     * 新增
//     *
//     * @param param
//     * @return
//     */
//    @Response
//    @PostMapping("/exam/warehouse")
//    @ApiOperation("新增")
//    public boolean insert(@RequestBody ExamWarehouse param) {
//        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
//        return service.insert(param) != null;
//    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/exam/warehouse/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/exam/warehouse/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody ExamWarehouse param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.update(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/exam/warehouse/{id}")
    @ApiOperation("根据id查询")
    public ExamWarehouseVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/exam/warehouse/page")
    @ApiOperation("分页查询")
    public Page<ExamWarehouseVo> selectByCondition(@RequestBody(required = false) ExamWarehouseSearchVo param) {
        if (param == null)
            param = ExamWarehouseSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 列表查询，不分页
     *
     * @return
     */
    @Response
    @PostMapping("/exam/warehouse/list")
    @ApiOperation("列表查询，不分页")
    public List<ExamWarehouseVo> selectList(@RequestBody(required = false) ExamWarehouseSearchVo param) {
        if (param == null)
            param = ExamWarehouseSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }

    /**
     * 题库导入
     *
     * @param name
     * @param file
     * @return
     */
    @Response
    @PostMapping("/exam/warehouse/import")
    @ApiOperation("题库导入")
    public boolean importExcel(@ApiParam(name = "name", value = "题库名称") @RequestParam(value = "name") String name,
                               @ApiParam(name = "userType", value = "人员类型，0：在职员工，1：规培生，2：进修生，3：研究生") @RequestParam(value = "userType") Byte userType,
                               MultipartFile file) {
        return service.importExcel(userType, name, file);
    }

    /**
     * 导出
     *
     * @param warehouseId
     * @return
     */
    @Response
    @GetMapping("/exam/warehouse/export")
    @ApiOperation("导出")
    public void export(@ApiParam(name = "warehouseId", value = "题库id") @RequestParam(value = "warehouseId") Long warehouseId,
                       HttpServletResponse response) {
        service.export(warehouseId, response);
    }

}